#include "Connection.hpp"
void cb(mq::Channel::ChannelPtr &channel, const string consumer_tag, const mq::BasicProperties *bp, const string &body)
{
    cout << consumer_tag << "消费了消息：" << body << endl;
    channel->basicAck(bp->id());
}
int main(int argc, char *argv[])
{
    if (argc != 3)
        return -1;
    mq::AsyncWorker::AsyncWorkerPtr work = make_shared<mq::AsyncWorker>();
    mq::Connection::ConnectionPtr conn = make_shared<mq::Connection>("127.0.0.1", 8088, work);
    conn->connect();
    mq::Channel::ChannelPtr cp = conn->openChannel();
    google::protobuf::Map<string, string> args;
    cp->declareExchange("exchange1", mq::ExchangeType::TOPIC, true, false, args);
    cp->declareQueue("queue1", true, false, false, args);
    cp->declareQueue("queue2", true, false, false, args);
    cp->queueBind("exchange1", "queue1", "queue1");
    cp->queueBind("exchange1", "queue2", "news.music.#");
    auto Functor = bind(cb, cp, placeholders::_1, placeholders::_2, placeholders::_3);
    cp->basicConsume(argv[2], argv[1], false, Functor);
    while (1)
        std::this_thread::sleep_for(std::chrono::seconds(3));
    conn->closeChannel(cp);
    return 0;
}